package com.ebelter.bodyfatscale.ui.activity;

import android.view.View;
import android.widget.TextView;

import com.ebelter.bodyfatscale.R;
import com.ebelter.bodyfatscale.util.ActivityManagers;
import com.ebelter.bodyfatscale.util.StringUtils;
import com.ebelter.bodyfatscale.util.ToastUtil;
import com.ebelter.btlibrary.btble.common.Fields;
import com.ebelter.btlibrary.btble.impl.scale.ScaleMessageAnalyser;
import com.ebelter.btlibrary.util.SpUtil;
import com.ebelter.btlibrary.util.ULog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 设备绑定Activity，包含未绑定提示，设备搜索及绑定成功页
 * 只有未绑定时，才会进入这里
 */

public class BindDeviceSuccessActivity extends BaseActivity{

    private static final String TAG = "BindDeviceHintActivity";

    public static final String NAME="name";
    public static final String ADDRESS="address";


    @BindView(R.id.tv_ble_name_bound)
    TextView tv_ble_name_bound;

    @BindView(R.id.tv_ble_address_bound)
    TextView tv_ble_address_bound;

    @Override
    protected int loadLayoutById() {
        return R.layout.activity_bind_success;
    }



    @Override
    protected void initViews() {
    }


    private String name;
    private String address;

    @Override
    protected void initData() {
        name=getIntent().getStringExtra(NAME);
        address=getIntent().getStringExtra(ADDRESS);
        tv_ble_name_bound.setText(StringUtils.getResStr(R.string.scalename_name));
        tv_ble_address_bound.setText(address);
    }



    @OnClick({R.id.iv_back_bind,R.id.btn_next_bind})
    public void btClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back_bind:
               finish();
                break;
            case R.id.btn_next_bind:
               ULog.i(TAG,"----------完成---address="+address+"-------name="+name);
                SpUtil.writeString(Fields.DEVICE_MAC,address);
                SpUtil.writeString(Fields.DEVICE_Name,name);
                ScaleMessageAnalyser.getInstance().connectedBlueName = name;
                ActivityManagers.getInstance().closeActivity(BindDeviceActivity.TAG);
                ToastUtil.show(R.string.Paired);
                finish();
                break;

        }
    }





}
